import 'package:flutter/material.dart';

void main() {
  runApp(MainPage());
}
class MainPage extends StatefulWidget {
  MainPage({Key? key}) : super(key: key);

  @override
  _MainPageState createState() => _MainPageState();
}

class _MainPageState extends State<MainPage> {
  TextEditingController _usernameController = TextEditingController();
  TextEditingController _passwordController = TextEditingController();
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
       home:Scaffold(appBar:AppBar(title:Text("登录"),) ,
       body:Container(
        padding: EdgeInsets.all(20),
        color: Colors.white,
        child: Column(
          children: [
            TextFormField(
              controller: _usernameController,
              decoration: InputDecoration(
                labelText: "用户名",
                hintText: "请输入用户名",
                prefixIcon: Icon(Icons.person),
              ),
            ),
            TextFormField(
              controller: _passwordController,
              obscureText: true,
              decoration: InputDecoration(
                labelText: "密码",
                hintText: "请输入密码",
                prefixIcon: Icon(Icons.lock),
              ),
            ),
            SizedBox(height: 20,),
            ElevatedButton(
              onPressed: (){
                String username = _usernameController.text;
                String password = _passwordController.text;
                if(username.isEmpty){
                  ScaffoldMessenger.of(context).showSnackBar(
                    SnackBar(content: Text("请输入用户名"))
                  );
                  return;
                }
                if(password.isEmpty){
                  ScaffoldMessenger.of(context).showSnackBar(
                    SnackBar(content: Text("请输入密码"))
                  );
                  return;
                }
                print("username:$username,password:$password");
                // Navigator.pushNamed(context, "/home");
              },
              child: Text("登录"),
            ),
          ],
        ),
       ),
       ));  
  }
}